Deprecated [[lib]] in favor of [lib]
authorAlex Crichton <alex@alexcrichton.com>
Thu, 14 Aug 2014 06:08:02 +0000 (23:08 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 14 Aug 2014 06:10:16 +0000 (23:10 -0700)
src/cargo/core/manifest.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/toml.rs
tests/support/mod.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_git_deps.rs
tests/test_cargo_compile_path_deps.rs
tests/test_cargo_compile_plugins.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_run.rs
tests/test_cargo_test.rs

index c733f8962cfabda15c936e1e3b98039363b5ad01..5214862de6e1797411158425db17519a703617ce 100644 (file)
@@ -22,7 +22,7 @@ pub struct Manifest {
     doc_dir: Path,
     sources: Vec<SourceId>,
     build: Vec<String>,
-    unused_keys: Vec<String>,
+    warnings: Vec<String>,
 }
 
 impl Show for Manifest {
@@ -298,7 +298,7 @@ impl Manifest {
             doc_dir: doc_dir.clone(),
             sources: sources,
             build: build,
-            unused_keys: Vec::new(),
+            warnings: Vec::new(),
         }
     }
 
@@ -346,12 +346,12 @@ impl Manifest {
         self.build.as_slice()
     }
 
-    pub fn add_unused_key(&mut self, s: String) {
-        self.unused_keys.push(s)
+    pub fn add_warning(&mut self, s: String) {
+        self.warnings.push(s)
     }
 
-    pub fn get_unused_keys(&self) -> &[String] {
-        self.unused_keys.as_slice()
+    pub fn get_warnings(&self) -> &[String] {
+        self.warnings.as_slice()
     }
 }
 
index 44d9afb49f0fdf3c24a8e8692998df8971151d97..105ad094371feb66df5f2e40de3e8fe79fa15ec7 100644 (file)
@@ -66,8 +66,8 @@ pub fn compile(manifest_path: &Path,
     let package = try!(source.get_root_package());
     debug!("loaded package; package={}", package);
 
-    for key in package.get_manifest().get_unused_keys().iter() {
-        try!(shell.warn(format!("unused manifest key: {}", key)));
+    for key in package.get_manifest().get_warnings().iter() {
+        try!(shell.warn(key))
     }
 
     let user_configs = try!(config::all_configs(os::getcwd()));
index 20d62aae0794976a3d019e5c28532f7b1c5f5a9a..d39b613f87e0e73b5de724f25e926195f0c2729c 100644 (file)
@@ -104,7 +104,7 @@ pub fn to_manifest(contents: &[u8],
         None => {}
     }
     if manifest.get_targets().len() == 0 {
-        return Err(human(format!("either a [[lib]] or [[bin]] section must \
+        return Err(human(format!("either a [lib] or [[bin]] section must \
                                   be present")))
     }
     return Ok((manifest, paths));
@@ -125,7 +125,7 @@ pub fn to_manifest(contents: &[u8],
                     add_unused_keys(m, v, key.clone());
                 }
             }
-            _ => m.add_unused_key(key),
+            _ => m.add_warning(format!("unused manifest key: {}", key)),
         }
     }
 }
@@ -312,8 +312,13 @@ impl TomlManifest {
         // If we have a lib with a path, we're done
         // If we have a lib with no path, use the inferred lib or_else package name
 
+        let mut used_deprecated_lib = false;
         let lib = match self.lib {
             Some(ref libs) => {
+                match *libs {
+                    Many(..) => used_deprecated_lib = true,
+                    _ => {}
+                }
                 libs.as_slice().iter().map(|t| {
                     if layout.lib.is_some() && t.path.is_none() {
                         TomlTarget {
@@ -383,19 +388,24 @@ impl TomlManifest {
             try!(process_dependencies(&mut cx, true, self.dev_dependencies.as_ref()));
         }
 
+        let build = match project.build {
+            Some(SingleBuildCommand(ref cmd)) => vec!(cmd.clone()),
+            Some(MultipleBuildCommands(ref cmd)) => cmd.clone(),
+            None => Vec::new()
+        };
+
         let summary = Summary::new(&pkgid, deps.as_slice());
-        Ok((Manifest::new(
-                &summary,
-                targets.as_slice(),
-                &layout.root.join("target"),
-                &layout.root.join("doc"),
-                sources,
-                match project.build {
-                    Some(SingleBuildCommand(ref cmd)) => vec!(cmd.clone()),
-                    Some(MultipleBuildCommands(ref cmd)) => cmd.clone(),
-                    None => Vec::new()
-                }),
-           nested_paths))
+        let mut manifest = Manifest::new(&summary,
+                                         targets.as_slice(),
+                                         &layout.root.join("target"),
+                                         &layout.root.join("doc"),
+                                         sources,
+                                         build);
+        if used_deprecated_lib {
+            manifest.add_warning(format!("the [[lib]] section has been \
+                                          deprecated in favor of [lib]"));
+        }
+        Ok((manifest, nested_paths))
     }
 }
 
index 534a1406a9203242e660a30990d13c128556e0d6..0ae2c79b9b253bdb74bd9586574ebfc9635a50a1 100644 (file)
@@ -492,7 +492,7 @@ pub fn basic_lib_manifest(name: &str) -> String {
         version = "0.5.0"
         authors = ["wycats@example.com"]
 
-        [[lib]]
+        [lib]
 
         name = "{}"
     "#, name, name)
index 76c9ba901fae72b8c49332ece0922e3351966cf5..4124736c7a1c44d345e194611fe2bb2c88e4a5fc 100644 (file)
@@ -180,7 +180,7 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -383,7 +383,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
 
             baz = "0.5.0"
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -401,7 +401,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "baz"
         "#)
@@ -459,7 +459,7 @@ test!(cargo_compile_with_nested_deps_longhand {
 
             version = "0.5.0"
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -477,7 +477,7 @@ test!(cargo_compile_with_nested_deps_longhand {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "baz"
         "#)
@@ -933,7 +933,7 @@ test!(many_crate_types_old_style_lib_location {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "foo"
             crate_type = ["rlib", "dylib"]
@@ -971,7 +971,7 @@ test!(many_crate_types_correct {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "foo"
             crate_type = ["rlib", "dylib"]
@@ -1010,7 +1010,7 @@ test!(unused_keys {
             authors = ["wycats@example.com"]
             bulid = "foo"
 
-            [[lib]]
+            [lib]
 
             name = "foo"
         "#)
@@ -1030,7 +1030,7 @@ test!(unused_keys {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "foo"
             build = "foo"
@@ -1057,7 +1057,7 @@ test!(self_dependency {
 
             path = "."
 
-            [[lib]]
+            [lib]
 
             name = "test"
         "#)
@@ -1093,7 +1093,7 @@ test!(missing_lib_and_bin {
         "#);
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(101)
-                       .with_stderr("either a [[lib]] or [[bin]] section \
+                       .with_stderr("either a [lib] or [[bin]] section \
                                      must be present\n"));
 })
 
@@ -1174,7 +1174,7 @@ test!(verbose_release_build_deps {
             version = "0.0.0"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "foo"
             crate_type = ["dylib", "rlib"]
         "#)
@@ -1222,7 +1222,7 @@ test!(explicit_examples {
             version = "1.0.0"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "world"
             path = "src/lib.rs"
 
@@ -1414,7 +1414,7 @@ test!(simple_staticlib {
               authors = []
               version = "0.0.1"
 
-              [[lib]]
+              [lib]
               name = "foo"
               crate-type = ["staticlib"]
         "#)
@@ -1468,3 +1468,21 @@ test!(single_lib {
         .file("src/bar.rs", "");
     assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
 })
+
+test!(deprecated_lib {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+              [package]
+              name = "foo"
+              authors = []
+              version = "0.0.1"
+
+              [[lib]]
+              name = "foo"
+        "#)
+        .file("src/foo.rs", "");
+    assert_that(p.cargo_process("cargo-build"),
+                execs().with_status(0)
+                       .with_stderr("\
+the [[lib]] section has been deprecated in favor of [lib]\n"));
+})
index 107c6aa05de4cff4eb2de5b8360224ec466499d7..dfc4c0be3df2b4d24f5619a067aab3365a5b6ddd 100644 (file)
@@ -51,7 +51,7 @@ test!(cargo_compile_simple_git_dep {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep1"
             "#)
@@ -111,7 +111,7 @@ test!(cargo_compile_git_dep_branch {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep1"
             "#)
@@ -175,7 +175,7 @@ test!(cargo_compile_git_dep_tag {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep1"
             "#)
@@ -244,7 +244,7 @@ test!(cargo_compile_with_nested_paths {
                 version = "0.5.0"
                 path = "vendor/dep2"
 
-                [[lib]]
+                [lib]
 
                 name = "dep1"
             "#)
@@ -262,7 +262,7 @@ test!(cargo_compile_with_nested_paths {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep2"
             "#)
@@ -314,7 +314,7 @@ test!(cargo_compile_with_meta_package {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep1"
             "#)
@@ -330,7 +330,7 @@ test!(cargo_compile_with_meta_package {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
 
                 name = "dep2"
             "#)
@@ -490,7 +490,7 @@ test!(recompilation {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
                 name = "bar"
             "#)
             .file("src/bar.rs", r#"
@@ -593,7 +593,7 @@ test!(update_with_shared_deps {
                 version = "0.5.0"
                 authors = ["carlhuda@example.com"]
 
-                [[lib]]
+                [lib]
                 name = "bar"
             "#)
             .file("src/bar.rs", r#"
index b05e468e10333f8790c50e9e11d06b5aaa6a8529..978ad87b1f2fdc0e2f15d5cba784629531712e6f 100644 (file)
@@ -42,7 +42,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
             version = "0.5.0"
             path = "baz"
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -60,7 +60,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "baz"
         "#)
@@ -201,7 +201,7 @@ test!(cargo_compile_with_transitive_dev_deps {
 
             git = "git://example.com/path/to/nowhere"
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -252,7 +252,7 @@ test!(no_rebuild_dependency {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]] name = "bar"
+            [lib] name = "bar"
         "#)
         .file("bar/src/bar.rs", r#"
             pub fn bar() {}
@@ -311,7 +311,7 @@ test!(deep_dependencies_trigger_rebuild {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
             name = "bar"
             [dependencies]
             baz = "0.5.0"
@@ -327,7 +327,7 @@ test!(deep_dependencies_trigger_rebuild {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
             name = "baz"
         "#)
         .file("baz/src/baz.rs", r#"
@@ -413,7 +413,7 @@ test!(no_rebuild_two_deps {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
             name = "bar"
             [dependencies]
             baz = "0.5.0"
@@ -428,7 +428,7 @@ test!(no_rebuild_two_deps {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
             name = "baz"
         "#)
         .file("baz/src/baz.rs", r#"
@@ -481,7 +481,7 @@ test!(nested_deps_recompile {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [lib]
 
             name = "bar"
         "#)
@@ -520,7 +520,7 @@ test!(error_message_for_missing_manifest {
 
             path = "src/bar"
 
-            [[lib]]
+            [lib]
 
             name = "foo"
         "#)
index 1b7f7431cad30afd7dbea22bd2648d239429c87d..dfefeda271dd74b56d5c7a0c9456c8ccdb7dcdbf 100644 (file)
@@ -12,7 +12,7 @@ test!(plugin_to_the_max {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "foo_lib"
 
             [dependencies.bar]
@@ -38,7 +38,7 @@ test!(plugin_to_the_max {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             plugin = true
 
@@ -65,7 +65,7 @@ test!(plugin_to_the_max {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "baz"
             crate_type = ["dylib"]
         "#)
index 2067b4b70f1d31d96bc05794dd6c208d7995537a..09a8361e84760112b55e5ce89a06b8ef0f1c7228 100644 (file)
@@ -120,7 +120,7 @@ test!(plugin_deps {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             plugin = true
         "#)
@@ -198,7 +198,7 @@ test!(plugin_to_the_max {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             plugin = true
 
@@ -317,7 +317,7 @@ test!(plugin_with_extra_dylib_dep {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             plugin = true
 
@@ -344,7 +344,7 @@ test!(plugin_with_extra_dylib_dep {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "baz"
             crate_type = ["dylib"]
         "#)
index 51c4b22d5818ca65745365d7c98dde20bd0cf381..adc4f0c6ebb810cfb85e8996ab35effcb164d8e8 100644 (file)
@@ -104,7 +104,7 @@ test!(run_dylib_dep {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             crate-type = ["dylib"]
         "#)
index 1d551c6bc6a045c7449f1a6724370c79cfa1488b..d983f900bf4bd0125817778559f9e8ccee47672b 100644 (file)
@@ -223,7 +223,7 @@ test!(test_with_deep_lib_dep {
             [dependencies.foo]
             path = "../foo"
 
-            [[lib]]
+            [lib]
             name = "bar"
             doctest = false
         "#)
@@ -466,7 +466,7 @@ test!(lib_bin_same_name {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "foo"
             [[bin]]
             name = "foo"
@@ -569,7 +569,7 @@ test!(lib_with_standard_name2 {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "syntax"
             test = false
             doctest = false
@@ -636,7 +636,7 @@ test!(test_dylib {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "foo"
             crate_type = ["dylib"]
 
@@ -663,7 +663,7 @@ test!(test_dylib {
             version = "0.0.1"
             authors = []
 
-            [[lib]]
+            [lib]
             name = "bar"
             crate_type = ["dylib"]
         "#)